//
//  MyTabBarController.m
//  FrameWork
//
//  Created by mac on 2017/5/17.
//  Copyright © 2017年 Limiao. All rights reserved.
//

#import "MyTabBarController.h"
#import "XCNavigationController.h"
#import "ViewController.h"
#import "XCWeatherViewController.h"
#import "XCMineViewController.h"
#import "Constants.h"

@interface MyTabBarController ()

@property (assign,nonatomic) BOOL isShowAppUpdateAlertView;

@end

@implementation MyTabBarController

- (instancetype)init {
    if (self = [super init]) {
        self.tabBar.barTintColor = [UIColor whiteColor];
        [self setUpSubControllers];
    }
    return self;
}

- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)viewDidLoad {
    [super viewDidLoad];
}

#pragma mark - setUp
- (void)setUpSubControllers {
    // 日记
    XCNavigationController *noteVC= [[XCNavigationController alloc] initWithRootViewController:[[ViewController alloc] init]];
    noteVC.tabBarItem = [self tabBarItemWithTitle:@"日记" image:@"notebook_uns" selectedImage:@"notebook_s"];
    
    // 天气
    XCNavigationController *weatherVC = [[XCNavigationController alloc] initWithRootViewController:[[XCWeatherViewController alloc] init]];
    weatherVC.tabBarItem = [self tabBarItemWithTitle:@"天气" image:@"weather_uns" selectedImage:@"weather_s"];
    
    // 我的
    XCNavigationController *mineVC = [[XCNavigationController alloc] initWithRootViewController:[[XCMineViewController alloc] init]];
    mineVC.tabBarItem = [self tabBarItemWithTitle:@"我的" image:@"user_uns" selectedImage:@"user_s"];
    
    self.viewControllers = @[noteVC, weatherVC, mineVC];
}

- (UITabBarItem *)tabBarItemWithTitle:(NSString *)title image:(NSString *)image selectedImage:(NSString *)selectedImage {
    
    UITabBarItem *item = [[UITabBarItem alloc] initWithTitle:title
                                                       image:[[UIImage imageNamed:image] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]
                                               selectedImage:[[UIImage imageNamed:selectedImage] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    
    [item setTitleTextAttributes:@{
                                   NSForegroundColorAttributeName:DWRGBColor(51, 51, 51),
                                   }
                        forState:UIControlStateSelected];
    
    [item setTitleTextAttributes:@{
                                   NSForegroundColorAttributeName:DWRGBColor(183, 183, 183),
                                   }
                        forState:UIControlStateNormal];
    return item;
    
}

@end
